package com.example.dilidili_ting.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.WindowManager;
import android.widget.Toast;
import android.widget.VideoView;

import com.example.dilidili_ting.R;
import com.example.dilidili_ting.bean.MovieBeanTing;
import com.thecode.aestheticdialogs.AestheticDialog;
import com.thecode.aestheticdialogs.DialogStyle;
import com.thecode.aestheticdialogs.DialogType;

import java.util.List;

public class VideoPlayActivityTing extends AppCompatActivity {

    private VideoView videoViewTing;
    private MovieBeanTing movieBeanTing;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_play_ting);

        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        movieBeanTing = (MovieBeanTing) getIntent().getSerializableExtra("movieData");
        initView();
    }

    private void initView() {
        videoViewTing = (VideoView) findViewById(R.id.videoView_ting);
        play();
    }

    private void play() {
        if(TextUtils.isEmpty(movieBeanTing.getMovieUrl())){
            new AestheticDialog.Builder(this, DialogStyle.TOASTER, DialogType.ERROR)
                    .setTitle("ERROR")
                    .setMessage("本地没有此视频,无法播放")
                    .setDuration(1500)
                    .show();
            return;
        }
        videoViewTing.setVideoPath(movieBeanTing.getMovieUrl());
        videoViewTing.start();
    }

}